#include "PikeMob.h"
#include "ImgMgr.h"
#include "Player.h"

PikeMob::PikeMob() : Mob()
{

}

void PikeMob::init(const sf::Vector2f position, ImgMgr *imageManager)
{
    Mob::init(position, imageManager);
    m_heart = 5;
    m_maxHeart = 5;
    m_currentRender = 0;
    m_skin[0] = imageManager->getSprite(10);
    m_skin[0].setScale(2, 2);
    m_originPosition = position;
    m_skin[0].setPosition(position.x, position.y + 32);
}

void PikeMob::maj(Player *player, Level *level)
{
    if(player->getPosition().y < getPosition().y + 10)
    {
        int xPlayer = player->getPosition().x;
        int yPlayer = player->getPosition().y;
        int distance = std::sqrt((xPlayer - getPosition().x) * (xPlayer - getPosition().x) + (yPlayer - getPosition().y)*(yPlayer - getPosition().y));
        if(distance < 75)
        {
            if(getPosition().y > m_originPosition.y)
                m_skin[m_currentRender].setPosition(m_originPosition.x, m_originPosition.y);
            if(xPlayer + 5 < getPosition().x + 32 && xPlayer + 27 > getPosition().x && yPlayer + 5 < getPosition().y + 32 && yPlayer + 27 > getPosition().y)
            {
                if(m_clockTick.getElapsedTime().asMilliseconds() > 1000)
                {
                    player->modifyHeart(-1);
                    m_clockTick.restart();
                }
            }
        }
    }
    Mob::maj(player, level);
}
